package com.aerotechnic.util;

import java.sql.Connection;
import java.sql.DriverManager;

import com.dhtmlx.connector.*;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;

@WebServlet(name = "JSONDataServlet", urlPatterns = {"/data"})
@RequestMapping(value="/data")
public class JsonGanttDataServlet extends ThreadSafeConnectorServlet{
   @Override
    protected void configure(HttpServletRequest req, HttpServletResponse res) {
      Connection conn=null;
      try {
         Class.forName ("com.mysql.jdbc.Driver").newInstance ();
         conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ordo", "root", "");
      } catch (Throwable e) {
         e.printStackTrace();
      }
       
      JSONGanttConnector gantt = new JSONGanttConnector(conn, DBType.MySQL);
      gantt.servlet(req, res);
      
      gantt.mix("open", "1");
      //gantt.enable_order("sortorder");

      gantt.render_links("gantt_links", "id", "source,target,type");
      gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,parent");
   }
}